package com.chucang.shucang.common.security.service;

import com.chucang.shucang.common.security.entity.ShuCangUser;
import org.springframework.core.Ordered;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;

/**
 * @author flitsneak
 * @email flitsneak@gmail.com
 * @date 2022/9/16 15:23
 * @description 抽取扩展接口
 */
public interface ShuCangUserDetailsService extends UserDetailsService, Ordered {
    /**
     * 是否支持此客户端校验
     *
     * @param clientId 目标客户端
     * @return true/false
     */
    default boolean support(String clientId, String grantType) {
        return true;
    }

    /**
     * 排序值 默认取最大的
     *
     * @return 排序值
     */
    default int getOrder() {
        return 0;
    }

    /**
     * 通过用户实体查询
     *
     * @param shuCangUser shuCangUser
     * @return security用户
     */
    default UserDetails loadUserByUser(ShuCangUser shuCangUser) {
        return this.loadUserByUsername(shuCangUser.getUsername());
    }
}
